<?php

namespace App\Console\Commands;

use App\Models\DdbUser;
use App\Services\SmsService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use PhpOffice\PhpWord\TemplateProcessor;
use PhpOffice\PhpWord\PhpWord;

class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '测试';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $ddb_user = DdbUser::query()->first();
        if (!$ddb_user) {
            dd('未找到');
        }
        ini_set('pcre.backtrack_limit', 999999999);

    //     $phpWord = new PhpWord();
    //     $section = $phpWord->addSection();

    //     $html = new \PhpOffice\PhpWord\Shared\Html;
    //     // 获取 html 内容，根据自己实际情况修改即可
    //     // $wordData = $this->getHtmlInfo();
        
    //     // dd(file_exists(file_local_path('ddb_users/少年班学院党总支_1702628416.html')));
    //     $wordData = file_get_contents(file_local_path('ddb_users/少年班学院党总支_1702628416.html'));


    // // addHtml 函数请阅读源码，其中，第四个参数是 有（远程）图片的时候使用。
    // $html::addHtml($section, $wordData, true, false,'IMG_SRC_SEARCH');

    // // 将内容保存为 word 文档
    // $file_name = "测试_".date("Y年m月d日H时i分s秒").".docx";
    // $filepath = public_path($file_name);
    // $phpWord->save($filepath, 'Word2007');

        //实例化 phpword 类
        $phpWordProcessor = new TemplateProcessor(public_path('tpl/ddb_user_tpl.docx')); //加载模板文件
        $phpWordProcessor->setImageValue('照片替换区域请不要修改这里的文字',
        ['path'=>'http://zzbdy.test/demo6.jpeg',
         "wrappingStyle" => 'square',
        'align'=> 'bottom',
        'position' => 'relative', 'order' => '1', 'z-index' => '9999', 'width'=>110, 'height' => 170, 'ratio' =>false]);
        // $phpWordProcessor->setValue('jl','<p>123</p>');
        $phpWordProcessor->saveAs(public_path(time() . ".docx"));

        // $conn = oci_connect('USYS_LIANGZI', 'viet28.08nam', '222.195.70.55:1521/ykt');
        // if (!$conn) {
        // $e = oci_error();
        // print htmlentities($e['message']);
        // exit;
        // }else {
        // echo "连接oracle成功！";
        // }

        // echo "start\r\n";
        // $conn = DB::connection('oracle');

        // $table = 'v_yjs_zp';
        // try {
        //     $conn = DB::connection('oracle');
        // } catch (\Throwable $th) {
        //     dd('链接失败');
        //     return;
        // }

        // $data = $conn->table('usys_liangzi.'.$table)->limit(2)->get();
        // dd($data);
    }
}
